package com.pianzhu.blockchainemr.controller;

import com.pianzhu.blockchainemr.pojo.result.Result;
import com.pianzhu.blockchainemr.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/userInfo")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;
    @PostMapping("/changePassword")
    public Result changePassword(@RequestParam("username") String username , @RequestParam("newPassword") String newPassword) {
         Boolean flag = userInfoService.changePassword(username, newPassword);
         if (flag) {
             return Result.success();
         } else {
             return Result.error("修改密码失败");
         }
    }

    @PostMapping("/changeImg/uploadImg")
    public Result uploadImg(@RequestParam("file") MultipartFile file) {
        Boolean flag = userInfoService.uploadImg(file);
        if (flag) {
            return Result.success();
        }else{
            return Result.error("上传图片失败");
        }
    }

    @PostMapping("/changeImg/url")
    public Result changeImg(@RequestParam("img") String img) {
        Boolean flag = userInfoService.changeImg(img);
        if (flag) {
            return Result.success();
        } else {
            return Result.error("修改头像失败");
        }
    }
}
